﻿function initTextarea(obj, maxLength, rows) {
    obj.title = "Ctrl+↑/Ctrl+↓";
    if (rows) {
        obj.rows = rows;
    }
    var focused = false;
    obj.onfocus = function() {
        if (!focused) {
            this.rows = this.rows + 2;
            //this.style.border = "1px solid pink";
            focused = true;
        }
    }
    obj.onkeydown = function() {
        if (this.value.length > maxLength) {
            this.value = this.value.substring(0, maxLength);
        }
        var e = getEvent(arguments[0]);
        if (e.keyCode == 38 && e.ctrlKey && this.rows > 1) {
            this.rows--;
        }
        if (e.keyCode == 40 && e.ctrlKey) {
            this.rows++;
        }
    };
}

function getEvent(e) {
    if (window.event) {
        return window.event;
    }
    if (e) {
        return e;
    }
}

var submiting = false;

window.onload = function() {
    var submits = document.getElementsByTagName("input");
    for (var i = 0; i < submits.length; i++) {
        var btn = submits[i];
        if (btn.type == "submit") {
            btn.onclick = checkSubmiting;
        }
    }

    var txts = document.getElementsByTagName("textarea");
    for (var j = 0; j < txts.length; j++) {
        var txt = txts[j];
        if (txt.className == "textarea") {
            initTextarea(txt, 2000, 4);
        }
    }

    var pane = document.getElementById("popUp");
    if (pane) {
        pane.style.display = "block";
        /*
        if( window.createPopup)
        {      
        var oPopup = window.createPopup();
    
    var oPopBody = oPopup.document.body;
        oPopBody.style.backgroundColor = "yellow";
        oPopBody.style.border = "solid black 1px";
        oPopBody.innerHTML = pane.innerHTML;
        alert(oPopup.document.documentElement.offsetWidth);
        //
        oPopup.show(window.screen.width-250, 
        window.screen.height-200, 250, 200);            
        //oPopup.show(window);
        }
        else
        {        
  
}
        */
    }

}

function checkSubmiting() {
    if (submiting) {
        return false;
    }
    else {
        submiting = true;
        return true;
    }
}